package com.rui.study.algorithm.learn_栈单链表栈;

/**
 * @program: study_20180903
 * @description: 栈。单链表栈，线程不安全
 * @author: Yaowr
 * @create: 2018-10-24 15:58
 **/
public class Stack<E> {

    private Node head;

    private int size;

    public Stack() {
    }

    public boolean push(E e) {
        head = new Node<E>(e, head);
        size++;
        return true;
    }


    public E pop() {
        if (head == null)
            return null;
        Node p = head;
        head = head.next;
        size--;
        return (E) p.element;
    }

    public int size() {
        return size;
    }

    private class Node<E> {
        private Object element;
        private Node next;

        public Node(Object element, Node next) {
            this.element = element;
            this.next = next;
        }
    }
}
